﻿using Sys = System;
using SysCg = System.Collections.Generic;
using SysRef = System.Reflection;

namespace Godot.core
{
    using SysMethodInfo = System.Reflection.MethodInfo;

    public class MethodBindNative<T> : MethodBind
    { 
        protected SysMethodInfo _call_method;
        public delegate void testing(string z);

        public SysMethodInfo method
        {
            set
            {
                _call_method = value;
            }
        }

        public MethodInfo method_info
        {
            set
            {
                _argument_count = value.arguments.Count;
            }
        }

        public MethodBindNative()
        {
            this._const = false;
            this._call_method = null;
            this._default_arguments = new SysCg.List<Variant>();
        }

        public virtual Variant.Type gen_argument_type(int p_arg)
        {
		    return Variant.Type.NIL;
	    }

        public override string get_instance_type()
        {
            SysRef.MethodInfo mtd_get_type_static = typeof(T).GetMethod("get_type_static");
            if(mtd_get_type_static == null)
                throw new Sys.NotImplementedException();
            return (string)mtd_get_type_static.Invoke(null, null);
        }

        public override Variant call(Object p_object, Variant[] p_args, ref Variant.CallError r_error)
        {
            SysCg.List<object> argLs = new SysCg.List<object>();
            argLs.Add(p_args);
            argLs.Add(r_error);
            return (Variant) _call_method.Invoke(p_object, argLs.ToArray());
         }
    }
}
